package com.ruicar.afs.cloud.basic.proceeds.mq.fallback;

import com.ruicar.afs.cloud.basic.common.service.BasicReceiptRecordService;
import com.ruicar.afs.cloud.common.mq.rabbit.fallback.SendFallBack;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-07-02 14:39
 */
@Slf4j
public class ReceiptHandleCompleteFallBack implements SendFallBack {

    @Autowired
    private BasicReceiptRecordService basicReceiptRecordService;


    @Override
    public void errorHandler(int code, String exchange, String routeKey, String message) {
        if (basicReceiptRecordService.receiptHandleCompleteErrorHandle(message)){
            log.error("mq->发送消息失败，已经进入重新发送队列\ncode:{}\nexchange:{}\nrouterKey{}\n消息内容:{}",code,exchange,routeKey,message);
        }else{
            log.error("mq->发送消息失败\ncode:{}\nexchange:{}\nrouterKey{}\n消息内容:{}",code,exchange,routeKey,message);
        }
    }

    @Override
    public void successHandler(int code, String exchange, String routeKey, String message) {
        log.info("mq->发送消息成功\ncode:{}\nexchange:{}\nrouterKey{}\n消息内容:{}",code,exchange,routeKey,message);
    }
}
